#ifndef _OWN_CHIP_RTC_H_
#define _OWN_CHIP_RTC_H_

#include "stm32f4xx.h"
#include "stdint.h"
#include "device_resource.h"
void own_chip_rtc_init(void);
void own_chip_rtc_cycle(void);
/*----------------------------------------------------------
 * 用户接口：初始化 RTC（LSI 为时钟源，60 s 唤醒一次）
 *---------------------------------------------------------*/
void RTC_Init_LSI_1min(void);

/*----------------------------------------------------------
 * RTC 基础配置：分频 + 24h 格式
 *---------------------------------------------------------*/
void RTC_Config(void);

/*----------------------------------------------------------
 * 中断控制器：RTC_WKUP + EXTI22
 *---------------------------------------------------------*/
void RTC_NVIC_Config(void);

/* -------------- 时间写入 -------------- */
void OWN_CHIP_RTC_SetTime(uint8_t hour, uint8_t min, uint8_t sec);
/* -------------- 时间读取 -------------- */
void OWN_CHIP_RTC_GetTime(uint8_t *hour, uint8_t *min, uint8_t *sec);
/* -------------- 日期写入 -------------- */
void OWN_CHIP_RTC_SetDate(uint8_t year, uint8_t month, uint8_t date, uint8_t week);

/* -------------- 日期读取 -------------- */
void OWN_CHIP_RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *week);

void TIM1_Init_1ms(void);
static void TIM1_Config(void);
static void TIM1_NVIC_Config(void);
void rtc_vals_to_tm(uint8_t year, uint8_t mon, uint8_t day,
                    uint8_t hour, uint8_t min, uint8_t sec,
                    uint8_t wday, struct tm *tm);

/* ---------- tm → 散值 ---------- */
void tm_to_rtc_vals(const struct tm *tm,
                    uint8_t *year, uint8_t *mon, uint8_t *day,
                    uint8_t *hour, uint8_t *min, uint8_t *sec,
                    uint8_t *wday);
#endif // !_OWN_CHIP_RTC_H_
